{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7ecc7207",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-16T06:46:10.332046Z",
     "start_time": "2021-07-16T06:46:08.296274Z"
    }
   },
   "outputs": [],
   "source": [
    "from autogluon.tabular import TabularDataset, TabularPredictor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6bc8546b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-16T06:46:58.348088Z",
     "start_time": "2021-07-16T06:46:54.098157Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "train_data = TabularDataset('./data/zhidemai/train.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21370fd8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-16T06:47:01.557381Z",
     "start_time": "2021-07-16T06:47:01.542237Z"
    },
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "train_data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ba99057",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-16T06:47:02.571735Z",
     "start_time": "2021-07-16T06:47:02.533065Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "train_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec3eacc4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-16T06:47:13.690516Z",
     "start_time": "2021-07-16T06:47:13.685902Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "label = 'orders_3h_15h'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a225cdb6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-16T19:25:45.595950Z",
     "start_time": "2021-07-16T06:47:30.624411Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "save_path = 'agModels-zhidemai'  # specifies folder to store trained models\n",
    "predictor = TabularPredictor(label=label, path=save_path).fit(train_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fa84c4eb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-16T19:25:46.126045Z",
     "start_time": "2021-07-16T19:25:45.598171Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "test_data_nolab = TabularDataset('./data/zhidemai/test.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54cce4ce",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-16T19:25:51.661647Z",
     "start_time": "2021-07-16T19:25:46.128238Z"
    }
   },
   "outputs": [],
   "source": [
    "y_pred = predictor.predict(test_data_nolab)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca6cc9bf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-19T02:39:52.803717Z",
     "start_time": "2021-07-19T02:39:52.791822Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "y_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "240cd16c",
   "metadata": {},
   "outputs": [],
   "source": [
    "id_ = ['article_id']\n",
    "target = 'orders_3h_15h'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b4fd354e",
   "metadata": {},
   "outputs": [],
   "source": [
    "sub = test_data_nolab[id_].copy()\n",
    "sub[target] = list(y_pred.values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c59b336a",
   "metadata": {},
   "outputs": [],
   "source": [
    "sub.to_csv(\"./autogluon_sub.csv\", index = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c43926aa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b54628e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
